﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using models;

namespace yuejilalala
{
    public partial class order : System.Web.UI.Page
    {
        OrderManager manager = new OrderManager();
        CartMarager cartMarager = new CartMarager();
        int a = 1; //未支付
        int b = 2;//待发货
        int c = 3;//待收货
        int d = 0;//已支付
        public static string dizhi = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            dizhi = "images/";
            
            if (!IsPostBack)
            {
               
                    if (Session["sess"] == null)
                    {
                        Response.Redirect("Login.aspx");
                }
                if (Session["sessid"] != null)
                {

                    J_MiniCartNum.Text = cartMarager.CartCount((Session["sessid"].ToString())).ProPrice.ToString();//显示出购物车内物品.数量
                }

                userDl();
                abc();
            }
            
        }

        //登陆在左上方显示用户名方法					
        public void userDl()
        {
            if (Session["sess"] != null)
            {
                //用户存在则显示出来 并且隐藏注册和登陆显示
                User user = Session["sess"] as User;
                hl_dlm.Text = "用户名:" + user.UName;
                hl_dlm.Visible = true;//显示登陆名控件
                hl_dl.Visible = false;//请登陆隐藏
                hl_zc.Visible = false;//注册隐藏
            }
           
        }
      //private void getUsers()
      //  {

      //      User user = Session["sess"] as User;
      //      List<ddxq> list = new OrderManager().GetOrderss(user.Id);
      //      PagedDataSource pag = new PagedDataSource();
      //      pag.AllowPaging = true;//        设置允许分页

      //      pag.PageSize = 3;  //        每页显示为行
      //      pag.DataSource = list;  //   模板绑定数据源  
      //      zong.Text = pag.PageCount.ToString(); //        显示总共页数
      //      int CurrentPage;
      //      //        请求页码为不为null设置当前页，否则为第一页
      //      if (Request.QueryString["Page"] != null)
      //      {

      //          CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
      //      }
      //      else
      //      {
      //          CurrentPage = 1;
      //      }
      //      if (Request.QueryString["PageSize"] != null)
      //      {
      //          pag.PageSize = Convert.ToInt32(Request.QueryString["PageSize"]);
      //      }
      //      else
      //      {
      //          pag.PageSize = 3;
      //      }

      //      pag.CurrentPageIndex = CurrentPage - 1;  //   当前页所引为页码-1
      //      dangqian.Text = CurrentPage.ToString(); //        当前页
      //      if (!pag.IsFirstPage)
      //      {
      //          //            Request.CurrentExecutionFilePath为当前请求虚拟路径
      //          lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);
      //      }
      //      //   如果不是最后一页，通过参数Page设置下一页为当前页+1，否则不显示连接
      //      if (!pag.IsLastPage)
      //      {
      //          //    Request.CurrentExecutionFilePath为当前请求虚拟路径
      //          lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);
      //      }
      //      //首页
      //      first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
      //      //尾页
      //      end.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + pag.PageCount.ToString();

      //      if (Convert.ToInt32(HttpContext.Current.Request["page"]) > pag.PageCount)
      //      {

      //          first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
      //      }

      //      this.Repeater1.DataSource = pag;
      //      this.Repeater1.DataBind();
      //  }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            User user = Session["sess"] as User;
            string order = e.CommandArgument.ToString();
            if (e.CommandName == "update")
            {
                manager.DeleteOrdersss(order);
               
                    Response.Write("<script>alert('删除成功')</script>");
                    Repeater1.DataSource = manager.GetOrderss(user.Id);
                    Repeater1.DataBind();
                
            }
        }
        public void abc()
        {
            User user = Session["sess"] as User;
            int statea = a;
            int stateb = b;
            int statec = c;
            int stated = d;
            Repeater1.DataSource = manager.GetOrderss(user.Id);
            Repeater1.DataBind();

            Repeater3.DataSource = manager.GetOrderssstate(user.Id, statea);
            Repeater3.DataBind();
            Repeater5.DataSource = manager.GetOrderssstate(user.Id, stateb);
           Repeater5.DataBind();
            Repeater7.DataSource = manager.GetOrderssstate(user.Id, statec);
            Repeater7.DataBind();
            Repeater9.DataSource = manager.GetOrderssstate(user.Id, stated);
              Repeater9.DataBind();
            //getUsers();
        }
        int bjjj = 0;
      // List<string> listSum = new List<string>();
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                
                User user = Session["sess"] as User;
                Repeater rep = e.Item.FindControl("Repeater2") as Repeater;//找到里层的repeater对象  
                ddxq rowv = e.Item.DataItem as ddxq;//找到分类Repeater关联的数据项   
              
                string order = Convert.ToString(rowv.Dddxq); //获取填充子类的id   
                List<ddxq> orders= manager.GetSUM(order);
                // listSum.Add(orders[0].Sum.ToString());//将价格放入泛型集合中
                //((Label)e.Item.FindControl("lb_sum")).Text =listSum[bjjj];//读取泛型中的价格
                ((Label)e.Item.FindControl("lb_sum")).Text = orders[0].Sum.ToString();
                //bjjj++;
                rep.DataSource = manager.GetOrde(order);
                rep.DataBind();

            }
        }

        protected void Repeater3_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
          if(e.CommandName == "zf")
            {
                Response.Redirect("shoppay.aspx?ddh="+e.CommandArgument+"&&shdz=true");
            }
        }
       
        protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
              
                User user = Session["sess"] as User;
                Repeater rep = e.Item.FindControl("Repeater4") as Repeater ;//找到里层的repeater对象  
                ddxq rowv = e.Item.DataItem as ddxq;//找到分类Repeater关联的数据项   
                string order = Convert.ToString(rowv.Dddxq); //获取填充子类的id  
                List<ddxq> orders = manager.GetSUM(order);
                // listSum.Add(orders[0].Sum.ToString());//将价格放入泛型集合中
                //((Label)e.Item.FindControl("lb_sum")).Text =listSum[bjjj];//读取泛型中的价格
                ((Label)e.Item.FindControl("lb_sum")).Text = orders[0].Sum.ToString();
                rep.DataSource = manager.GetOrde(order);
                rep.DataBind();
            }
        }

        protected void Repeater9_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

            if (e.CommandName=="pj")
            {
                string ab = e.CommandArgument.ToString();
                Response.Redirect("comremark.aspx?ddbh="+ab);
            }
        }

        protected void Repeater9_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                User user = Session["sess"] as User;
                Repeater rep = e.Item.FindControl("Repeater10") as Repeater;//找到里层的repeater对象  
                ddxq rowv = e.Item.DataItem as ddxq;//找到分类Repeater关联的数据项   
                string order = Convert.ToString(rowv.Dddxq); //获取填充子类的id  
                List<ddxq> orders = manager.GetSUM(order);
                // listSum.Add(orders[0].Sum.ToString());//将价格放入泛型集合中
                //((Label)e.Item.FindControl("lb_sum")).Text =listSum[bjjj];//读取泛型中的价格
                ((Label)e.Item.FindControl("lb_sum")).Text = orders[0].Sum.ToString();
                rep.DataSource = manager.GetOrde(order);
                rep.DataBind();
            }
        }

        protected void Repeater5_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }

        protected void Repeater5_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                User user = Session["sess"] as User;
                Repeater rep = e.Item.FindControl("Repeater6") as Repeater;//找到里层的repeater对象  
                ddxq rowv = e.Item.DataItem as ddxq;//找到分类Repeater关联的数据项   
                string order = Convert.ToString(rowv.Dddxq); //获取填充子类的id   
                List<ddxq> orders = manager.GetSUM(order);
                // listSum.Add(orders[0].Sum.ToString());//将价格放入泛型集合中
                //((Label)e.Item.FindControl("lb_sum")).Text =listSum[bjjj];//读取泛型中的价格
                ((Label)e.Item.FindControl("lb_sum")).Text = orders[0].Sum.ToString();
                rep.DataSource = manager.GetOrde(order);
                rep.DataBind();
            }
        }

        protected void Repeater7_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string orders = e.CommandArgument.ToString();
            if (e.CommandName == "qrsh")
            {
                manager.updateByidsta(orders);
                
                Response.Redirect("order.aspx");
            }

        }

        protected void Repeater7_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                User user = Session["sess"] as User;
                Repeater rep = e.Item.FindControl("Repeater8") as Repeater;//找到里层的repeater对象  
                ddxq rowv = e.Item.DataItem as ddxq;//找到分类Repeater关联的数据项   
                string order = Convert.ToString(rowv.Dddxq); //获取填充子类的id  
                List<ddxq> orders = manager.GetSUM(order);
                // listSum.Add(orders[0].Sum.ToString());//将价格放入泛型集合中
                //((Label)e.Item.FindControl("lb_sum")).Text =listSum[bjjj];//读取泛型中的价格
                ((Label)e.Item.FindControl("lb_sum")).Text = orders[0].Sum.ToString();
                rep.DataSource = manager.GetOrde(order);
                rep.DataBind();
            }
        }
    }
}